package Animation;

import GameElements.CTDCreep;
import IO.Path;
import IO.Waypoint;
import Properties.props;

/**
 * Interpolates position with every Tick
 *
 */
public class CreepWalk {
	public static CTDCreep Interpolate(CTDCreep creep, Path wp, char mapElement)
	{
		props constants = new props();
		float aktPosX = creep.getAbsoluteX();
		float aktPosY = creep.getAbsoluteY();
		float walkSpeed = creep.getWalkSpeed();
		int current_wpID = wp.getWayPointIDByCoordinates(creep.getPosX(), creep.getPosY());
		if(current_wpID +1 <= wp.getMaxWayPoint())
		{
			Waypoint nextPoint = wp.getWayPoint(current_wpID+1);
			if(mapElement == 'S')
			{
				int newX = nextPoint.getX() - wp.getWayPoint(current_wpID).getX();
				int newY = nextPoint.getY() - wp.getWayPoint(current_wpID).getY();
				aktPosX += newX*walkSpeed;
				aktPosY += newY*walkSpeed;
			}
			if(mapElement == 'v')
				aktPosY += walkSpeed;
			if(mapElement == '<')
				aktPosX -= walkSpeed;
			if(mapElement == '>')
				aktPosX += walkSpeed;
			if(mapElement == '^')
				aktPosY -= walkSpeed;
			int _posX = (int) (aktPosX/props.FieldInPixels);
			int _posY = (int) (aktPosY/props.FieldInPixels);
			creep.setAbsoluteX((int) aktPosX );
			creep.setAbsoluteY((int) aktPosY );
			if(_posX == nextPoint.getX()&& _posY == nextPoint.getY())
			{
				creep.setPosX(_posX);
				creep.setPosY(_posY);
			}
		}
		return creep;		
	}

	
}
